package org.geom;

public class Line2D {

	public Point2D point1;
	public Point2D point2;

	public Line2D() {
	} 

	public Line2D(Point2D ppoint, Point2D point) { 
		this.point1 = ppoint;
		this.point2 = point;
	}
	
	public Line2D(Point3D ppoint, Point3D point) { 
		this.point1 = new Point2D(ppoint.x, ppoint.y);
		this.point2 = new Point2D(point.x, point.y);
	}

	public Point2D getMiddle() {
		return new Point2D((point1.x+point2.x)/2, (point1.y+point2.y)/2);
	}

	public String toString() {
		return "("+point1.toString()+" , "+point2.toString()+")"; 
	}

	public Point2D inbetween(float percentage) {
		/* percentage must be between 0 and 1*/
		float dx = Math.abs(point2.x - point1.x);
		float dy = Math.abs(point2.y - point1.y);
		float directionX = 1;
		float directionY = 1;
		Point2D ret = new Point2D();

		if(point1.x > point2.x) directionX = -1;
		if(point1.y > point2.y) directionY = -1;

		ret.x = point1.x + directionX * (dx * percentage );
		ret.y = point1.y + directionY * (dy * percentage );

		return ret;
	}

}




